<?php echo $header; ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('view/image/product.png');"><?php echo $heading_title; ?></h1>
    <div class="buttons"><a onclick="location = '<?php echo $insert; ?>'" class="button"><span><?php echo $button_insert; ?></span></a><a onclick="$('#form').attr('action', '<?php echo $copy; ?>'); $('#form').submit();" class="button"><span><?php echo $button_copy; ?></span></a><a onclick="$('form').submit();" class="button"><span><?php echo $button_delete; ?></span></a></div>
  </div>
  <div class="content">
    <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
      <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>            
            <td class="left" width="40%"><?php if ($sort == 'pd.name') { ?>
              <a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
              <?php } ?></td>
            <td class="left"><?php if ($sort == 'cd.category_name') { ?>
              <a href="<?php echo $sort_category; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_category; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_category; ?>"><?php echo $column_category; ?></a>
              <?php } ?></td>
            <td class="left"><?php if ($sort == 'p.sort_order') { ?>
              <a href="<?php echo $sort_order; ?>" class="<?php echo strtolower($order); ?>">Sort Order</a>
              <?php } else { ?>
              <a href="<?php echo $sort_order; ?>">Sort Order</a>
              <?php } ?></td>     
            <td class="left"><?php if ($sort == 'p.status') { ?>
              <a href="<?php echo $sort_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_status; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_status; ?>"><?php echo $column_status; ?></a>
              <?php } ?></td>
            <td class="right"><?php echo $column_action; ?></td>
          </tr>
        </thead>
        <tbody>
          <tr class="filter">
            <td></td>            
            <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" /></td>
            <td>
                <!-- input type="text" name="filter_category" value="<?php echo $filter_category; ?>" / -->
                <select name="filter_category">
                    <option value="*"></option>
                    <?php foreach ($categories as $category) { ?>                        
                        <?php if ($category['category_id'] == $filter_category) { ?>
                            <option value="<?php echo $category['category_id']; ?>" selected="selected"><?php echo $category['name']; ?></option>
                        <?php } else { ?>
                            <option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option> 
                        <?php } ?>
                    <?php } ?>                
                </select>
            </td>
            <td>&nbsp;</td>
            <td><select name="filter_status">
                <option value="*"></option>
                <?php if ($filter_status) { ?>
                    <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <?php } else { ?>
                    <option value="1"><?php echo $text_enabled; ?></option>
                <?php } ?>
                <?php if (!is_null($filter_status) && !$filter_status) { ?>
                    <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                    <option value="0"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select></td>
            <td align="right"><a onclick="filter();" class="button"><span><?php echo $button_filter; ?></span></a></td>
          </tr>
          
          <?php if ($contents) { ?>
          <?php foreach ($contents as $content) { ?>
          <tr>
            <td style="text-align: center;"><?php if ($content['selected']) { ?>
              <input type="checkbox" name="selected[]" value="<?php echo $content['content_id']; ?>" checked="checked" />
              <?php } else { ?>
              <input type="checkbox" name="selected[]" value="<?php echo $content['content_id']; ?>" />
              <?php } ?></td>            
            <td class="left"><?php echo $content['name']; ?></td>
            <td class="left">
                <?php foreach ($content['categories'] as $category) { ?>
                    <?php echo $category['name'];?><br>
                <?php } ?>
            </td>
            <td class="left"><?php echo $content['sort_order']; ?></td>
            <td class="left"><?php echo $content['status']; ?></td>
            <td class="right"><?php foreach ($content['action'] as $action) { ?>
              [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
              <?php } ?></td>
          </tr>
          <?php } ?>
          <?php } else { ?>
          <tr>
            <td class="center" colspan="7"><?php echo $text_no_results; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
    </form>
    <div class="pagination"><?php echo $pagination; ?></div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=content/content&token=<?php echo $token; ?>';
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
    
    /*
    var filter_category = $('input[name=\'filter_category\']').attr('value');	
	if (filter_category) {
		url += '&filter_category=' + encodeURIComponent(filter_category);
	}
    */
    var filter_category = $('select[name=\'filter_category\']').attr('value');  
    if (filter_category != '*') {
        url += '&filter_category=' + encodeURIComponent(filter_category);
    }
    
	var filter_status = $('select[name=\'filter_status\']').attr('value');	
	if (filter_status != '*') {
		url += '&filter_status=' + encodeURIComponent(filter_status);
	}	

	location = url;
}
//--></script>

<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});

$('#form select').change(function(e) {
    filter(); 
});
//--></script>
<?php echo $footer; ?>